package properties_gin

type CorsProperty struct {
	AllowCors bool `mapstructure:"allow-cors" json:"allow-cors" yaml:"allow-cors"`
	//Access-Control-Allow-Origin: *
	AccessControlAllowOrigin string `mapstructure:"Access-Control-Allow-Origin" json:"Access-Control-Allow-Origin" yaml:"Access-Control-Allow-Origin"`
	//Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, PATCH
	AccessControlAllowMethods string `mapstructure:"Access-Control-Allow-Methods" json:"Access-Control-Allow-Methods" yaml:"Access-Control-Allow-Methods"`
	//Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With
	AccessControlAllowHeaders string `mapstructure:"Access-Control-Allow-Headers" json:"Access-Control-Allow-Headers" yaml:"Access-Control-Allow-Headers"`
	//Access-Control-Expose-Headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers
	AccessControlExposeHeaders string `mapstructure:"Access-Control-Expose-Headers" json:"Access-Control-Expose-Headers" yaml:"Access-Control-Expose-Headers"`
	//Access-Control-Max-Age: 86400
	AccessControlMaxAge           string `mapstructure:"Access-Control-Max-Age" json:"Access-Control-Max"`
	AccessControlAllowCredentials bool   `mapstructure:"Access-Control-Allow-Credentials" json:"Access-Control-Allow-Credentials" yaml:"Access-Control-Allow-Credentials"`
}

func (c *CorsProperty) GetAccessControlAllowOrigin() string {
	if c.AccessControlAllowOrigin == "" {
		return "*"
	}
	return c.AccessControlAllowOrigin
}

func (c *CorsProperty) GetAccessControlAllowMethods() string {
	if c.AccessControlAllowMethods == "" {
		return "POST, GET, OPTIONS, PUT, DELETE, PATCH"
	}
	return c.AccessControlAllowMethods
}

func (c *CorsProperty) GetAccessControlAllowHeaders() string {
	if c.AccessControlAllowHeaders == "" {
		return "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With"
	}
	return c.AccessControlAllowHeaders
}

func (c *CorsProperty) GetAccessControlExposeHeaders() string {
	if c.AccessControlExposeHeaders == "" {
		return "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers"
	}
	return c.AccessControlExposeHeaders
}

func (c *CorsProperty) GetAccessControlMaxAge() string {
	if c.AccessControlMaxAge == "" {
		return "86400"
	}
	return c.AccessControlMaxAge
}

func (c *CorsProperty) GetAccessControlAllowCredentials() bool {
	return c.AccessControlAllowCredentials
}
